package fightplan.actions;

import java.awt.event.ActionEvent;

import javax.swing.JOptionPane;

import fightplan.ModeControl;
import fightplan.views.MainView;

@SuppressWarnings("serial")
public class NewTournamentAction extends UndoableAction {

	private MainView mainView;

	public NewTournamentAction(MainView mainView) {
		super("Neues Turnier", mainView, "Altes Turnier wiederherstellen", "Neues Turnier wiederherstellen");
		this.mainView = mainView;
	}

	public boolean doAction(ActionEvent actionEvent) {
		boolean confirm = JOptionPane.showConfirmDialog(mainView, "Wollen Sie das aktuelle Turnier wirklich löschen?",
				"Turnier löschen?", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION;
		if (!confirm)
			return false;

		ModeControl modeControl = ModeControl.getInstance();
		modeControl.choose();
		if (modeControl.getTournament() == null)
			return false;

		mainView.getTournament().setValue(modeControl.getTournament());

		return true;
	}

	//

	public UndoRedoManager getUndoRedoManager() {
		return mainView.getUndoRedoManager();
	}

}